package com.zq.product.controller;


import com.github.pagehelper.PageInfo;
import com.zq.common.util.Result;
import com.zq.product.dao.entity.ProductSku;
import com.zq.product.dao.entity.ProductSpec;
import com.zq.product.dao.vo.ProductItemVo;
import com.zq.product.service.IProductSpecService;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品规格 前端控制器
 * </p>
 *
 * @author 张乔
 * @since 2025-05-13
 */
@RestController
@RequestMapping("/product/product-spec")
public class ProductSpecController {

    @Resource
    private IProductSpecService productSpecService;

//    分页条件查询
    @GetMapping("/getAllPage/{page}/{limit}")
    public Result<Object> getAllPage(@PathVariable Integer page,
                                     @PathVariable Integer limit,
                                     @RequestParam(value = "name",required = false) String name) {
        PageInfo<ProductSpec> pageInfo= productSpecService.getAllPage(page,limit,name);
    return Result.successData(pageInfo);
    }

//    查询所有
    @GetMapping("/getAllSpec")
    public Result<Object> getAll() {
        List<ProductSpec> pageInfo= productSpecService.list();
    return Result.successData(pageInfo);
    }




//    新增
    @PostMapping("/save")
    public Result<String> save(@RequestBody ProductSpec productSpec) {
        productSpecService.save(productSpec);
    return Result.success();
    }

//    修改
    @PutMapping("/updateById")
    public Result<String> update(@RequestBody ProductSpec productSpec) {
        productSpecService.updateById(productSpec);
    return Result.success();
    }
//    删除
    @DeleteMapping("/deleteById/{id}")
    public Result<String> delete(@PathVariable Long id) {
        productSpecService.removeById(id);
    return Result.success();
}






}
